import { Controller, Get, Param, ParseIntPipe, Query, Req } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiSecurityAuth } from '~/common/decorators/swagger.decorator';
import { HistoryService } from './history.service';

// 定义一个简单的DTO以供复制
class QueryHistoryDto {
  page: number = 1;
  pageSize: number = 10;
}

@ApiTags('历史记录')
@ApiSecurityAuth()
@Controller('user-history')  // 使用标准路径格式，不含api前缀
export class HistoryController {
  constructor(private readonly historyService: HistoryService) {}

  @Get(':id')
  @ApiOperation({ summary: '获取用户编辑历史' })
  @ApiResponse({
    status: 200,
    description: '获取成功',
  })
  async getUserHistory(
    @Param('id', ParseIntPipe) id: number,
    @Query() query: QueryHistoryDto,
    @Req() req
  ) {
    console.log(`
_______________________________
|                             |
| HISTORY ROUTE WAS MATCHED!  |
| Path: ${req.url}
| Method: ${req.method}
| User ID: ${id}
| Query: ${JSON.stringify(query)}
|_____________________________|
    `);
    
    return this.historyService.getUserHistory(
      id, 
      query.page || 1,
      query.pageSize || 10
    );
  }
} 